package com.trkj.controller;


import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.CcHospapply;
import com.trkj.pojos.CcPatient;
import com.trkj.pojos.JlIccard;
import com.trkj.pojos.Tbdepartment;
import com.trkj.pojos.Tbstaff;
import com.trkj.service.CcHospapplyService;
import com.trkj.service.CcPatientService;
import com.trkj.service.CcPaymentService;
import com.trkj.service.CcPrepaymentService;
import com.trkj.vo.HwcStaffVO;
import com.trkj.vo.Result;

@Controller
public class CCTotalController {
	@Autowired
	private CcHospapplyService cchospService;
	@Autowired
	private CcPatientService ccPatientService;
	@Autowired
	private CcPaymentService ccPaymentService;
	@Autowired
	private CcPrepaymentService ccPrepaymentService;
	

	@RequestMapping("/tohost")
	public String tohost(){
		return "cc_host";
	}
	
	@RequestMapping("/tocc_doctor_advice")
	public String toccdoctoradvice(){
		return "cc_doctor_advice";
	}
	@RequestMapping("/cc_toouthospital")
	public String toouthospital(){
		return "cc_outhospital";
	}
	@RequestMapping("/tocc_casrhistory")
	public String tocc_casrhistory(){
		return "cc_casrhistory";
	}
	@RequestMapping("/tocc_patientcheck")
	public String tocc_patientcheck(){
		return "cc_patirntcheck";
	}
	@RequestMapping("/tocc_payment")
	public String topayment(){
		ccPrepaymentService.updatePpremark();
		return "cc_payment";
	}
	@RequestMapping("/cc_berth")
	public String ccberth(){
		return "cc_berth";
	}
	@RequestMapping("/cc_patient")
	public String ccpatient(){
		
		return "cc_patient";
	}
	@RequestMapping("/tocc_botu")
	public String cc_botu(){
		
		return "cc_botu";
	}
	@RequestMapping("/tocc_inhospital")
	public String tocc_inhospital(){
		return "cc_inhospital";
	}
	@RequestMapping("/tocc_inhospitalByOne")
	public @ResponseBody CcHospapply tocc_inhospitalByOne(String hospid){
		return cchospService.queryByOne(hospid);
	}
	@RequestMapping("/tocc_queryAllhosp")
	public @ResponseBody Map<String, Object> toqueryAll(int page,int rows){
		return cchospService.queryAll(page,rows);
	}
	@RequestMapping("/tocc_queryAllapply")
	public @ResponseBody Map<String, Object> toqueryAllapply(int page,int rows){
		return cchospService.queryAllapply(page,rows);
	}
	@RequestMapping("/tocc_queryhaname")
	public @ResponseBody Map<String, Object> queryhaname(int page, int rows,String haname){
		//System.out.println("123455"+haname);
		return cchospService.queryhaname(page, rows,haname);
	}
	@RequestMapping("/tocc_queryhmedicalid")
	public @ResponseBody Map<String, Object> queryHmedicalid(int page, int rows,String hmedicalid){
		//System.out.println("122"+hmedicalid);
		return cchospService.queryHmedicalid(page, rows,new BigDecimal(hmedicalid));
	}
	@RequestMapping("/delcchosp")
	public @ResponseBody Result delNewCurPurPlan(Long[] list,String hpdoctorid){
		if(list.length>0){
			cchospService.alertAsk(list, hpdoctorid);
			return new Result(true, "取消成功！");		
		}else{
			return new Result(true, "取消失败！");		
		}
		
		
	}
	@RequestMapping("/addccpatient")
	public @ResponseBody Result addNewCurPurPlan(String applyid,String hpdoctorid,
			String icid,String pname,String tel,String tname,
			String psex,String pweight, String pofficesid,String pmoney,String padoctorid){
		if(hpdoctorid.length()>0&&icid.length()>0&&pofficesid.length()>0){
			cchospService.alertRequest(applyid, hpdoctorid);
			CcPatient ccpatient=new CcPatient();
			ccpatient.setIcid(new BigDecimal(icid));
			ccpatient.setPname(pname);
			ccpatient.setPsex(psex);
			ccpatient.setTel(tel);
			ccpatient.setPpdate(new  Date());
			ccpatient.setTname(tname);
			ccpatient.setPadoctorid(new BigDecimal(padoctorid));
			ccpatient.setPweight(pweight);
			ccpatient.setPofficesid(new BigDecimal(pofficesid));
			JlIccard icCard=ccPatientService.queryOneCard(Long.parseLong(icid));
			ccpatient.setPcard(icCard.getIIdentityCard());
			ccpatient.setPaage(icCard.getIAge().toString());
			ccpatient.setAddress(icCard.getIAddress());
			long ppatientid=ccPatientService.addCcPatient(ccpatient);
			if(pmoney.length()>0){
				ccPaymentService.addccpayment(new BigDecimal(pmoney), new BigDecimal(hpdoctorid), ppatientid);
				
			}
			return new Result(true, "办理成功！");		
		}
		return new Result(false, "办理失败！");		
	}
	@RequestMapping("/queryTbdepartment")
	public @ResponseBody  Map<String, Object>  queryTbdepartment(int page, int rows){
			return cchospService.queryTbdepartment(page,rows);
	}
	@RequestMapping("/queryTbstaff")
	public @ResponseBody List<HwcStaffVO> queryTbstaff(){
			return cchospService.queryTbstaff();
	}
}
